package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	var filePath string = "./4.txt"
	file, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
	if err != nil {
		fmt.Println(err)
	}
	writer := bufio.NewWriter(file)
	var strLine string = "this is a line,the index is "
	var lineIndex, str string
	for i := 1; i <= 10; i++ {
		lineIndex = strconv.FormatInt(int64(i), 10)
		str = strLine + lineIndex + "\r\n"
		writer.WriteString(str)
	}
	writer.Flush()
	file.Close()
	file, err = os.OpenFile(filePath, os.O_RDONLY, 0666)
	if err != nil {
		fmt.Println(err)
	}
	reader := bufio.NewReader(file)
	for {
		str, err = reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		fmt.Print(str)
	}
}
